window.axios = require('axios');
require('promise.prototype.finally').shim();
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
// Add a request interceptor
window.axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
});

// Add a response interceptor
window.axios.interceptors.response.use(function (response) {
    console.log(response);
    //登录超时
    if (response.data.code == -100 && res.data.jurl) {
        setTimeout(function () {
            window.location.href = res.data.jurl;
        }, 3000);
    }
    if (response.data.code) {
        return Promise.reject(response.data);
    }
    return response.data;
}, function (error) {
    return Promise.reject({code: -404, msg: '网络请求异常', data: error});
});
Promise.prototype.showMsg = function (flag) {
    this.catch(function (data) {
        console.log(data);

        layer.msg(data.msg, {icon: 7, time: 2000});
    });
    if (flag) {
        this.then(data => {
            layer.msg(data.msg, {icon: 7, time: 2000});
        });
    }
};

